<template>
<div class="OrderDetailIndex">
<div class="detail_left">
  <div class="content">
    <div class="head">
    <h1>订单标题：{{orderDetailInfo.title}}</h1>
    <span><i class="el-icon-sell"></i>收藏</span>
    <span><i class="el-icon-warning-outline"></i>举报</span>
    </div>
    <div class="tag">
    <el-tag v-for="t in orderDetailInfo.labels" :key="t.id" size="medium " type="danger">{{ t.content }}</el-tag>
    </div>
    <div class="information">
      <h3>备注：</h3>
      <div class="text">
        <span>{{ orderDetailInfo.content }}</span>
      </div>
    </div>
    <div class="photograph">
      <h3>订单图片：</h3>
      <span v-for="x in orderDetailInfo.pictures" :key="x.id">
      <el-image
          style="width: 200px; height: 200px"
          :src="x.url"
          :preview-src-list="[x.url]">
      </el-image>
        </span>
    </div>
    <h3 class="address"><i class="el-icon-location-information"></i>详细地址：{{orderDetailInfo.address}}</h3>
    <div class="time">
    <span class="me-pull-right me-article-count">
        <i class="el-icon-time"></i>&nbsp;预计开始时间：{{ orderDetailInfo.startTime }}
         <i class="el-icon-time"></i>&nbsp;---预计结束时间：{{ orderDetailInfo.endTime }}
      </span>
    </div>
    </div>
  <el-divider></el-divider>
  <div class="userInfo">
        <div class="block">
          <el-avatar :size="100"  :src="userDetailInfo.photoUrl"></el-avatar>
      </div>
    <div class="userName">
      <h3>{{ userDetailInfo.userName }}<i class="el-icon-star-on"></i></h3>
      <el-tag  size="small" type="info">刚刚活跃</el-tag>
      <div class="prestige">
      <span>信誉度：</span>
        <el-rate
            v-model="userDetailInfo.creditScore"
            disabled
            show-score
            text-color="#ff9900"
            score-template="{value}">
        </el-rate>
      </div>
    </div>
  </div>
  <div v-if="userDetailInfo.id !== getuserInfo.id" class="btn">
    <el-button plain @click="HandContact">联系对方</el-button>
    <el-button type="warning" @click="HandPlaceOrder" plain>立即接单</el-button>
  </div>
</div>
<div class="detail_right">
  <OrderBar style="width: 100%;float: right;clear: right"></OrderBar>
  <div class="detail_right_bottom"></div>
</div>
</div>
</template>

<script>
import {mapState} from "vuex";
import {reqAddAssUser, reqPlaceOrder} from "@/api";
import OrderBar from "@/views/home/OrderBar.vue";

export default {
  name: "OrderDetailIndex",
  components:{
    OrderBar
  },
  data() {
    return {
      orderDetail: {},
      value: 3.7,
    }
  },
  mounted() {
    let userId = this.$route.params.userId;
    this.$store.dispatch('OrderDetail', userId);
  },
  computed: {
    ...mapState({
      orderDetailInfo: state => state.helpOrderItems.orderDetailInfo,
      userDetailInfo: state => state.helpOrderItems.userDetail,
      getuserInfo: state => state.user.userInfo,
      users: state => state.chat.users,
    })
  },
  methods: {
    async HandPlaceOrder() {
      let userId = this.orderDetailInfo.userCode
      let initiateId = this.orderDetailInfo.initiateOrderCode
      let detailId = this.orderDetailInfo.id
      console.log(userId)
      console.log(initiateId)
      console.log(detailId)
      await reqPlaceOrder(userId, initiateId, detailId).then(() => {
        this.$message({message: '接单成功', type: 'success', showClose: true});
        this.$router.push("/myOrder/mySnapshotOrder")
        // this.$router.push(goPath);
      }).catch((error) => {
        if (error !== 'error') {
          this.$message({message: error, type: 'error', showClose: true});
        }
      })

    },
    async HandContact() {
      try {
        // 查询当前用户对象有没有历史聊过天
        this.users.forEach((item) => {
          if (item.userId === this.userDetailInfo.id) {
            this.$store.dispatch('UpdateChatUser', item.userInfo);
            this.$router.push("/chat");
            throw new Error('true');
          }
        })
        //把对方id，订单详情传回后台
        await reqAddAssUser(this.userDetailInfo.id, this.orderDetailInfo.id, this.getuserInfo.id)
        this.$store.dispatch('UpdateChatUser', this.userDetailInfo);
        this.$router.push("/chat");
      } catch (e) {
        console.log('出错了')
      }
    }
  }
}
</script>

<style scoped>
.OrderDetailIndex{
  width: 1184px;
  margin: 0 auto;
  height: 820px;
  margin-top: 20px;
}
.detail_left{
  border-radius: 20px 20px 0 0;
  height: 820px;
  width: 70%;
  float: left;
  background-color: white;
}
.detail_left .content{
  margin-top: 20px;
}
.detail_left .content .head h1{
  float: left;
  width: 40%;
  margin-left: 30px;
}
.detail_left .content .head span{
  float: right;
  width: 40px;
  margin-right: 20px;
}
.tag{
  clear: left;
  width: 50%;
  padding-top: 20px;
}
.el-tag{
  margin-left: 30px;
}
.information{
  margin-top: 20px;
  margin-left: 30px;
}
.information h3{
  float: left;
}
.information .text{
  float: right;
  border: 1px solid #FFB3B3;
  border-radius: 11px 11px 11px 11px;
  margin-right: 14%;
  width: 80%;
  height: 60px;
  margin-top: -5px;
  background-color: #FFB3B3;
}
.information .text span{
  margin-left: 10px;
  padding-top: 5px;
}
.address{
  margin-top: 20px;
  margin-left: 30px;
}
.photograph{
  padding-top: 20px;
  margin-left: 30px;
  clear: right;
}
.photograph .el-image{
  margin-top: 10px;
  margin-left: 5.5%;
}
.userInfo{
  width: 90%;
  height: 120px;
  margin-left: 9%;
}
.userInfo .block{
 padding-top: 10px;
  float: left;
}
.userName{
  float: left;
  margin-top: 30px;
  margin-left: 40px;
}
.userName h3{
  margin-top: 2px;
  float: left;
}
.userName el-avatar{
  float: right;
  padding-top: 10px;
}
.prestige{
  width: 250px;
margin-top: 10px;
}
.prestige span{
  float: left;
}
.prestige .el-rate{
  margin-left: 50px;
}
.time{
margin-top: 10px;
  margin-left: 30px;
}
.btn{
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 60px;
}
.btn .el-button{
  margin-left: 40px;
}

/*右边*/
.detail_right{
  border-radius: 20px 20px 0 0;
  height: 820px;
  width: 28%;
  float: right;
  box-sizing: border-box;
}
.detail_right_bottom{
  clear: right;
  border-radius: 20px;
  height: 40%;
  background-color: #2c3e50;
  margin-top: 490px;
}
</style>
